package thread;

public class SyncDemo2 {
    public static void main(String[] args) {

    shop s1 = new shop();

    Thread t1 = new Thread("陈冠希"){
        @Override
        public void run() {
            s1.buy();
        }
    };
    Thread t2 = new Thread("吴彦祖"){
        @Override
        public void run() {
            s1.buy();
        }
    };

    t1.start();
    t2.start();
    }

}
class shop{
    public void buy(){

        try {
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"正在挑选衣服");
            Thread.sleep(5000);

            synchronized (this) {
                System.out.println(t.getName() + "正在试衣服");
                Thread.sleep(5000);
            }
            System.out.println(t.getName()+"正在结账");
            Thread.sleep(5000);
            System.out.println(t.getName()+"离开");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}